<?php 
include 'header.php'; 
?>

<h2><?= isset($edit) ? 'Edit' : 'Add' ?> Category</h2>

<?= isset($message) && !empty($message) ? '<div id="alert">' . $message . '</div>' : '' ?>

<form id="addcat" action="<?=base_url()?>index.php/admin/category/<?= isset($edit) ? 'update' : 'add' ?>" method="POST">
    <div id="catname">Category Name: <input name="title" value="<?= isset($edit->title) ? $edit->title : '' ?>" /></div>
    <div id="parentcat">Parent Category: <select name="parentid">
        <option <?= isset($edit->parentid) && $edit->parentid == '-1' ? 'SELECTED' : '' ?> value="-1">Top Level Category</option>
        <? foreach($categories as $category) {
                if (!in_array("Events", explode(" --- ", $category->sortname)))
                        echo "<option asdf='" . $edit->parentid . " " . $category->catid . "' ";
			if (isset($edit->parentid) && $edit->parentid == $category->catid)
			    echo 'SELECTED';
			echo " value='" . $category->catid . "'>" . $category->tabs . $category->catname . "</option>";
        } ?>
    </select></div>
    <div id="desc">Description:<br /><textarea name="description"><?= isset($edit->description) ? $edit->description : '' ?></textarea></div>
    <?= isset($edit->id) ? "<input type='hidden' name='id' value='" . $edit->id . "' />" : "" ?>
    <div id="buttons"><input type="submit" value="<?= isset($edit) ? 'Update' : 'Add' ?> Category" /> <input type="submit" name="Cancel" value="Cancel" /></div>
    
</form>
	<br />	
<h1>Categories</h1>


<div id="content">
<form name="categoriesform" id="categoriesform" action="<?php echo base_url(); ?>index.php/admin/category/delete" method="POST">
		<div id="buttons">
			
			<input type="submit" name="button" value="Delete Selected" />
			
			<br />&nbsp;<br /><span style="display: none;" id="selecting">Select: <span id="selall"><a href="#" onclick="return false" style="color: black">All</a></span>, <span id="selnone"><a href="#" onclick="return false" style="color: black">None</a></span>
			</span>

		</div>

<table cellspacing=0 ><tbody id="the-list">
	<?php if (!empty($categories)) {
                foreach ($categories as $category) {
                
                        //No Events, just categories!
                        if (!in_array('Events', explode(' --- ', $category->sortname))) {
                ?>
                
                
        
			<tr>	
		<td><input id="select_<?=$category->catid?>" name="checkall[<?=$category->catid?>]" value="<?=$category->catid?>" type="checkbox" /></td>

		<td class="date"><?=$category->count?> item<?= $category->count != 1 ? 's' : '' ?></td>
				<td class="pagetitle"><?= $category->tabs . "&raquo; " . anchor('admin/category/edit/' . $category->catid ,$category->catname, 'style="text-decoration: none"') ?>
					<span class="snippet">
                                            <?= $category->description == "No description." ? "<em>" : "" ?>
                                            <?= anchor('admin/category/edit/' . $category->catid ,
                                                       substr($category->description,
                                                              0,
                                                              55 - strlen($category->catname)),
                                                        'style="text-decoration: none; color: grey;"')
                                            ?>
                                            <? $length = 55 - strlen($category->catname); ?>
                                            <?= strlen($category->description) > $length  ? '...' : '' ?>
                                            <?= $category->description == "No description." ? "</em>" : "" ?>
                                        </span>
                                </td>
				<td class="author" style="text-align: right; padding-right: 25px"></td>
				<td><a href="<?php echo base_url(); ?>index.php/category/<?=$category->catid?>" title="View Category"><img src='<?php echo base_url(); ?>images/view.png' alt='view' /></a></td>
				<td><a href="<?php echo base_url(); ?>index.php/admin/category/edit/<?=$category->catid?>" title="Edit Category"><img src='<?php echo base_url(); ?>images/edit.png' alt='edit' /></a></td></td>
		
		</tr>
	<?php }}} ?>
			

			
<input type='hidden' name='offset' id='offset' value=<?php echo $offset; ?> />
</tbody>
</table>
</form>
<?php
include 'footer.php';
?>